﻿using System;
using System.Collections;
using System.Web.UI;

namespace Salient.Web.Administration
{
    public partial class navigationBar : NavigationBar
    {
        private const string Category_Application = "Application";
        private const string Category_Home = "Home";
        private const string Category_Provider = "Provider";
        private const string Category_Security = "Security";
        private ArrayList _categoryList = new ArrayList();
        private string _directionality;
        private int _selectedIndex;

        public string Directionality
        {
            get
            {
                if (String.IsNullOrEmpty(_directionality))
                {
                    _directionality =
                        ((string)GetGlobalResourceObject("GlobalResources", "HtmlDirectionality")).ToLower();
                }
                return _directionality;
            }
        }

        public string GetCenterClass(int index)
        {
            if (index == _selectedIndex)
                return "selTabCenter";
            else
                return "deSTabCenter";
        }

        public string GetLeftClass(int index)
        {
            if (Directionality == "rtl")
            {
                if (index == _selectedIndex)
                    return "selTabRight";
                else
                    return "deSTabRight";
            }
            else
            {
                if (index == _selectedIndex)
                    return "selTabLeft";
                else
                    return "deSTabLeft";
            }
        }

        public string GetHelpImage()
        {
            if (Directionality == "rtl")
            {
                return Common.GetNormalizedUrl("images/Help.jpg");
            }
            else
            {
                return Common.GetNormalizedUrl("images/HelpIcon_solid.gif");
            }
        }

        public string GetLeftImage(int index)
        {
            if (Directionality == "rtl")
            {
                if (index == _selectedIndex)
                    return Common.GetNormalizedUrl("images/selectedTab_rightCorner.gif");
                else
                    return Common.GetNormalizedUrl("images/unSelectedTab_rightCorner.gif");
            }
            else
            {
                if (index == _selectedIndex)
                    return Common.GetNormalizedUrl("images/selectedTab_leftCorner.gif");
                else
                    return Common.GetNormalizedUrl("images/unSelectedTab_leftCorner.gif");
            }
        }

        public string GetRightClass(int index)
        {
            if (Directionality == "rtl")
            {
                if (index == _selectedIndex)
                    return "selTabLeft";
                else
                    return "deSTabLeft";
            }
            else
            {
                if (index == _selectedIndex)
                    return "selTabRight";
                else
                    return "deSTabRight";
            }
        }

        public string GetRightImage(int index)
        {
            if (Directionality == "rtl")
            {
                if (index == _selectedIndex)
                    return Common.GetNormalizedUrl("images/selectedTab_leftCorner.gif");
                else
                    return Common.GetNormalizedUrl("images/unSelectedTab_leftCorner.gif");
            }
            else
            {
                if (index == _selectedIndex)
                    return Common.GetNormalizedUrl("images/selectedTab_rightCorner.gif");
                else
                    return Common.GetNormalizedUrl("images/unSelectedTab_rightCorner.gif");
            }
        }


        public string GetLocalizedString(string title)
        {
            if (title == Category_Home ||
                title == Category_Security ||
                title == Category_Application ||
                title == Category_Provider)
            {
                return (string)GetGlobalResourceObject("GlobalResources", title);
            }
            else
            {
                return title;
            }
        }

        public string GetAltText(string altText)
        {
            return (string)GetGlobalResourceObject("GlobalResources", altText);
        }

        private void Page_Load()
        {
            if (!Page.IsPostBack)
            {
                _categoryList = new ArrayList();

                var tempPair = new Pair(Category_Home, "default.aspx");
                _categoryList.Add(tempPair);

                tempPair = new Pair(Category_Security, "security/security.aspx");
                _categoryList.Add(tempPair);

                tempPair = new Pair(Category_Application, "appConfig/appConfigHome.aspx");
                _categoryList.Add(tempPair);

                tempPair = new Pair(Category_Provider, "providers/chooseProviderManagement.aspx");
                _categoryList.Add(tempPair);

                imageRepeater.DataSource = _categoryList;
                DataBind();
            }
        }

        public override void SetSelectedIndex(int index)
        {
            _selectedIndex = index;
        }

        public string MouseOver(int index)
        {
            if (index == _selectedIndex)
            {
                return String.Empty;
            }
            return "this.className='hoverTabCenter';" +
                   "document.getElementById('left" + index + "').className='hoverTabLeft';" +
                   "document.getElementById('right" + index + "').className='hoverTabRight';";
        }

        public string MouseOut(int index)
        {
            if (index == _selectedIndex)
            {
                return String.Empty;
            }
            return "this.className='deSTabCenter';" +
                   "document.getElementById('left" + index + "').className='deSTabLeft';" +
                   "document.getElementById('right" + index + "').className='deSTabRight';";
        }
    }
}